﻿$(
    function () {
        $('#MessageDialog').dialog({
            autoOpen: false,
            width: 300,
            closeOnEscape: true,
            bgiframe: true
        });
    }
);

/* 
Message for Page 
Note:the dialog container on the materPage
isDefault: boolen 

How to Use:
1) Use Default width and height:
Example: 
ShowDialogMessage("right/warn/error","message");
   
2) User-define width or height,
Note:It must to use ConfigDialogMessage() function before ShowDialogMessage() function
   
Example: user define
ConfigDialogMessage(200/null,null/200);   --if (null,null):aoto width and auto height
ShowDialogMessage("right/warn/error","message");
*/
var vIsDefault = true;
function ShowDialogMessage(resultType, message) {
    message = HTMLDecode(message);
    var dialogObj = $('#MessageDialog');
    if (vIsDefault == true && resultType.toLowerCase() != "error") {
        dialogObj.dialog({
            autoOpen: false,
            width: 300,
            height: 130,
            modal: false
        });
    }
    else {
        dialogObj.dialog({
            autoOpen: false,
            width: 300,
            height: 130,
            modal: true
        });
    }
    vIsDefault = true;
    var vLogoImage = "";
    var vButtonImage = "";
    resultType = resultType.toLowerCase();
    switch (resultType) {
        case "right":
            vLogoImage = "/Content/images/prompt_right.gif";
            vButtonImage = "/Content/images/close_button.gif";
            break;
        case "warn":
            vLogoImage = "/Content/images/prompt_warn.gif";
            vButtonImage = "/Content/images/close_button.gif";
            break;
        case "error":
            vLogoImage = "/Content/images/prompt_error.gif";
            vButtonImage = "/Content/images/close_button.gif";
            break;
    }
    message = message.replace(/(\r\n)|(\n\r)|(\r)|(\n)/g, "<br/>");
    var vDialog = "<div class='prompt_content'>";
    vDialog += " <table cellpadding='0' cellspacing='0' border='0' class='prompt_table' style='margin-top: 8px;'>";
    vDialog += " <tr>";
    vDialog += " <td width='10%' valign='middle'>";
    vDialog += " <img src='" + vLogoImage + "' />";
    vDialog += "  </td>";
    vDialog += "  <td width='90%' class='prompt_padding'>";
    vDialog += "  <span id='succeededMsg'>" + message + "</span>";  //message的信息格式需需过虑
    vDialog += "  </td>";
    vDialog += "  </tr>";
    vDialog += "  <tr>";
    vDialog += "  <td height='20px'> &nbsp;";
    vDialog += "  </td>";
    vDialog += "  </tr>";
    vDialog += " </table>";
    vDialog += " <div style='position:absolute; bottom:5px;right:18px'> <img src='" + vButtonImage + "' style='cursor:pointer' onclick='closeMessageDialog()' /></div>";
    vDialog += "</div>";
    $("#MessageDialog").html(vDialog)
    dialogObj.dialog('open');
}

// config  DialogMessage
function ConfigDialogMessage(aWidth, aHeight) {
    vIsDefault = false;
    var vType = 0;
    if (aWidth != null && aHeight == null) {
        if (aWidth > 0) {
            vType = 1;
        }
    }
    else if (aWidth == null && aHeight != null) {
        if (aHeight > 0) {
            vType = 2;
        }
    }
    else if (aWidth != null && aHeight != null) {
        if (aWidth > 0 && aHeight == 0) {
            vType = 3;
        } else if (aWidth == 0 && aHeight > 0) {
            vType = 4;
        }
        else if (aWidth > 0 && aHeight > 0) {
            vType = 5;
        }
    }
    switch (vType) {
        case 1:
        case 3:
            $('#MessageDialog').dialog({
                width: aWidth
            });
            break;
        case 2:
        case 4:
            $('#MessageDialog').dialog({
                height: aHeight
            });
            break;
        case 5:
            $('#MessageDialog').dialog({
                width: aWidth,
                height: aHeight
            });
            break;
    }
}

function closeMessageDialog() {
    $("#iframetop").remove();
    $("#MessageDialog").dialog('close');
}

function HTMLDecode(text) {
    var temp = document.createElement("div");
    temp.innerHTML = text;
    var output = temp.innerText || temp.textContent;
    temp = null;
    return output;
}


